home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / kernel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  11.1 KB  |  391 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. #ifndef NO_MEMORY_H
  23. #include <memory.h>
  24. #endif
  25.  
  26. #ifdef UNIX
  27. #include <defs.h>
  28. #include <term.h>
  29. #endif
  30.  
  31. /* undefine any macros for functions defined in this module */
  32. #undef    def_prog_mode
  33. #undef    def_shell_mode
  34. #undef    reset_prog_mode
  35. #undef    reset_shell_mode
  36. #undef    resetty
  37. #undef    savetty
  38. #undef    getsyx
  39. #undef    setsyx
  40. #undef    ripoffline
  41. #undef    curs_set
  42. #undef    napms
  43.  
  44. /* undefine any macros for functions called by this module if in debug mode */
  45. #ifdef PDCDEBUG
  46. #  undef    move
  47. #  undef    wmove
  48. #endif
  49.  
  50. #ifdef PDCDEBUG
  51. char *rcsid_kernel  = "$Id$";
  52. #endif
  53.  
  54. /*man-start*********************************************************************
  55.  
  56.   Name:                                                        kernel
  57.  
  58.   Synopsis:
  59.       int def_prog_mode(void);
  60.       int def_shell_mode(void);
  61.       int reset_prog_mode(void);
  62.       int reset_shell_mode(void);
  63.       int resetty(void);
  64.       int savetty(void);
  65.   ***    int getsyx(int y, int x);
  66.   ***    int setsyx(int y, int x);
  67.   ***    int ripoffline(int line, init(*int)(WINDOW *,int));
  68.       int curs_set(int visibility);
  69.       int napms(int ms);
  70.  
  71.   X/Open Description:
  72.      The def_prog_mode() and def_shell_mode() functions save the 
  73.      current terminal modes as the "program" (in curses) or
  74.      "shell" (not in curses) state for use by the reset_prog_mode()
  75.      and reset_shell_mode() functions.  This is done automatically by
  76.      initscr().
  77.  
  78.      The reset_prog_mode() and reset_shell_mode() functions restore 
  79.      the terminal to "program" (in curses) or "shell" (not in curses)
  80.      state.  These are done automatically by endwin()
  81.      and doupdate() after an endwin(), so they would normally not
  82.      be called before these functions.
  83.  
  84.      The savetty() and resetty() routines save and restore the state of 
  85.      the terminal modes. The savetty() function saves the current state 
  86.      in a buffer and resetty() restores the state to what it was at the 
  87.      last call to savetty().
  88.  
  89.   PDCurses Description:
  90.      FYI: It is very unclear whether savetty() and resetty() functions
  91.      are a duplication of the reset_prog_mode() and reset_shell_mode() 
  92.      functions or whether this is a backing store type of operation.  
  93.      At this time, they are implemented similar to the reset_*_mode() 
  94.      routines.
  95.  
  96.      The curs_set() routine is used to set the visibility of the cursor.
  97.      The cursor can be made invisible, normal or highly visible by setting
  98.      the parameter to 0, 1 or 2 respectively. If an invalid value is passed
  99.      the function will set the cursor to "normal".
  100.  
  101.   X/Open Return Value:
  102.      All functions return OK on success and ERR on error except curs_set()
  103.      which returns the previous visibility.
  104.  
  105.   X/Open Errors:
  106.      No errors are defined for this function.
  107.  
  108.   Portability                             X/Open    BSD    SYS V
  109.                                           Dec '88
  110.       def_prog_mode                         Y        Y       Y
  111.       def_shell_mode                        Y        Y       Y
  112.       reset_prog_mode                       Y        Y       Y
  113.       reset_shell_mode                      Y        Y       Y
  114.       resetty                               Y        Y       Y
  115.       savetty                               Y        Y       Y
  116.       getsyx                                -        -      3.0
  117.       setsyx                                -        -      3.0
  118.       ripoffline                            -        -      3.0
  119.       curs_set                              -        -      3.0
  120.       napms                                 Y        Y       Y
  121.  
  122. **man-end**********************************************************************/
  123.  
  124. #ifndef UNIX
  125. /***********************************************************************/
  126. int    def_prog_mode(void)
  127. /***********************************************************************/
  128. {
  129. #ifdef PDCDEBUG
  130.     if (trace_on) PDC_debug("def_prog_mode() - called\n");
  131. #endif
  132.  
  133. #ifdef    FLEXOS
  134.     _flexos_16bitmode();
  135. #endif
  136.     c_pr_tty.been_set = TRUE;
  137.  
  138.     memcpy(&c_pr_tty.saved, &_cursvar, sizeof(SCREEN));
  139.  
  140.     return( OK );
  141. }
  142. #endif
  143.  
  144. #ifndef UNIX
  145. /***********************************************************************/
  146. int    def_shell_mode(void)
  147. /***********************************************************************/
  148. {
  149. #ifdef PDCDEBUG
  150.     if (trace_on) PDC_debug("def_shell_mode() - called\n");
  151. #endif
  152.  
  153. #ifdef    FLEXOS
  154.     _flexos_8bitmode();
  155. #endif
  156.     c_sh_tty.been_set = TRUE;
  157.  
  158.     memcpy(&c_sh_tty.saved, &_cursvar, sizeof(SCREEN));
  159.  
  160.     return( OK );
  161. }
  162. #endif
  163.  
  164. #ifndef UNIX
  165. /***********************************************************************/
  166. int    reset_prog_mode(void)
  167. /***********************************************************************/
  168. {
  169. #ifdef PDCDEBUG
  170.     if (trace_on) PDC_debug("reset_prog_mode() - called\n");
  171. #endif
  172.  
  173.     if    (c_pr_tty.been_set == TRUE)
  174.     {
  175.  
  176.         memcpy(&_cursvar, &c_pr_tty.saved, sizeof(SCREEN));
  177.  
  178.         mvcur(0, 0, c_pr_tty.saved.cursrow, c_pr_tty.saved.curscol);
  179.         if (PDC_get_ctrl_break() != c_pr_tty.saved.orgcbr)
  180.             PDC_set_ctrl_break(c_pr_tty.saved.orgcbr);
  181.         if (c_pr_tty.saved.raw_out)
  182.             raw();
  183.         if (c_pr_tty.saved.visible_cursor)
  184.             PDC_cursor_on();
  185.         _cursvar.font = PDC_get_font();
  186.         PDC_set_font(c_pr_tty.saved.font);
  187. #if !defined (XCURSES)
  188. #  ifndef EMXVIDEO
  189.         if (!PDC_scrn_modes_equal (PDC_get_scrn_mode(),  c_pr_tty.saved.scrnmode))
  190.             PDC_set_scrn_mode(c_pr_tty.saved.scrnmode);
  191. #  endif
  192. #endif
  193.         PDC_set_rows(c_pr_tty.saved.lines);
  194.     }
  195. #ifdef    FLEXOS
  196.     _flexos_16bitmode();
  197. #endif
  198.     return( OK );
  199. }
  200. #endif
  201.  
  202. #ifndef UNIX
  203. /***********************************************************************/
  204. int    reset_shell_mode(void)
  205. /***********************************************************************/
  206. {
  207. #ifdef PDCDEBUG
  208.     if (trace_on) PDC_debug("reset_shell_mode() - called\n");
  209. #endif
  210.  
  211.     if    (c_sh_tty.been_set == TRUE)
  212.     {
  213.  
  214.         memcpy(&_cursvar, &c_sh_tty.saved, sizeof(SCREEN));
  215.  
  216.         mvcur(0, 0, c_sh_tty.saved.cursrow, c_sh_tty.saved.curscol);
  217.         if (PDC_get_ctrl_break() != c_sh_tty.saved.orgcbr)
  218.             PDC_set_ctrl_break(c_sh_tty.saved.orgcbr);
  219.         if (c_sh_tty.saved.raw_out)
  220.             raw();
  221.         if (c_sh_tty.saved.visible_cursor)
  222.             PDC_cursor_on();
  223.         _cursvar.font = PDC_get_font();
  224.         PDC_set_font(c_sh_tty.saved.font);
  225. #if !defined (XCURSES)
  226. #  ifndef EMXVIDEO
  227.         if (!PDC_scrn_modes_equal (PDC_get_scrn_mode(),  c_sh_tty.saved.scrnmode))
  228.             PDC_set_scrn_mode(c_sh_tty.saved.scrnmode);
  229. #  endif
  230. #endif
  231.         PDC_set_rows(c_sh_tty.saved.lines);
  232.     }
  233. #ifdef    FLEXOS
  234.     _flexos_8bitmode();
  235. #endif
  236.     return( OK );
  237. }
  238. #endif
  239.  
  240. /***********************************************************************/
  241. int    resetty(void)
  242. /***********************************************************************/
  243. {
  244. #ifdef PDCDEBUG
  245.     if (trace_on) PDC_debug("resetty() - called\n");
  246. #endif
  247.  
  248. #ifndef UNIX
  249.     if    (c_save_tty.been_set == TRUE)
  250.     {
  251.         memcpy(&_cursvar, &c_save_tty.saved, sizeof(SCREEN));
  252.  
  253.         mvcur(0, 0, c_save_tty.saved.cursrow, c_save_tty.saved.curscol);
  254.         if (PDC_get_ctrl_break() != c_save_tty.saved.orgcbr)
  255.             PDC_set_ctrl_break(c_save_tty.saved.orgcbr);
  256.         if (c_save_tty.saved.raw_out)
  257.             raw();
  258.         if (c_save_tty.saved.visible_cursor)
  259.             PDC_cursor_on();
  260.         _cursvar.font = PDC_get_font();
  261.         PDC_set_font(c_save_tty.saved.font);
  262. #if !defined (XCURSES)
  263. #  ifndef EMXVIDEO
  264.         if (!PDC_scrn_modes_equal (PDC_get_scrn_mode(), c_save_tty.saved.scrnmode))
  265.             PDC_set_scrn_mode(c_save_tty.saved.scrnmode);
  266. #  endif
  267. #endif
  268.         PDC_set_rows(c_save_tty.saved.lines);
  269.     }
  270. #endif
  271.     return( c_save_tty.been_set ? OK : ERR );
  272. }
  273. /***********************************************************************/
  274. int    savetty(void)
  275. /***********************************************************************/
  276. {
  277. #ifdef PDCDEBUG
  278.     if (trace_on) PDC_debug("savetty() - called\n");
  279. #endif
  280.  
  281.     c_save_tty.been_set = TRUE;
  282.     memcpy(&c_save_tty.saved, &_cursvar, sizeof(SCREEN));
  283.     return( OK );
  284. }
  285. /***********************************************************************/
  286. int    curs_set(int visibility)
  287. /***********************************************************************/
  288. {
  289. #ifdef OS2
  290. # ifndef EMXVIDEO
  291.  VIOCURSORINFO pvioCursorInfo;
  292. # endif
  293. #endif
  294.  int start,end,hidden=0;
  295.  int ret_vis;
  296.  
  297. #ifdef PDCDEBUG
  298.     if (trace_on) PDC_debug("curs_set() - called: visibility=%d\n",visibility);
  299. #endif
  300.  
  301.     ret_vis = _cursvar.visibility;
  302.     _cursvar.visibility = visibility;
  303.  
  304. #ifdef UNIX
  305.     switch(visibility)
  306.     {
  307.         case 0:  /* invisible */
  308.             if (cursor_invisible != NULL)
  309.                 putp(cursor_invisible);
  310.             break;
  311.         case 2:  /* highly visible */
  312.             if (cursor_visible != NULL)
  313.                 putp(cursor_visible);
  314.             break;
  315.         default:  /* normal visibility */
  316.             if (cursor_visible != NULL)
  317.                 putp(cursor_visible);
  318.             break;
  319.     }
  320.     return(OK);
  321. #endif
  322.  
  323. #if defined(DOS) || defined(OS2)
  324.     switch(visibility)
  325.     {
  326.         case 0:  /* invisible */
  327. # ifdef OS2
  328. #  ifdef EMXVIDEO
  329.             start = end = 0;
  330. #  else
  331.             start = _cursvar.font / 4;
  332.             end = _cursvar.font;
  333. #  endif
  334. # else
  335.             start = 32;
  336.             end = 32;  /* was 33 */
  337. # endif
  338.             hidden = (-1);
  339.             break;
  340.         case 2:  /* highly visible */
  341.             start = 2;   /* almost full-height block */
  342.             end = _cursvar.font-1;
  343.             break;
  344.         default:  /* normal visibility */
  345.             start = _cursvar.font - 4;
  346.             end = _cursvar.font-1;
  347.             break;
  348.     }
  349.  
  350. # ifdef OS2
  351. #  ifdef EMXVIDEO
  352.     if (hidden)
  353.         v_hidecursor();
  354.     else
  355.         v_ctype (start, end);
  356. #  else
  357.     pvioCursorInfo.yStart = (USHORT)start;
  358.     pvioCursorInfo.cEnd = (USHORT)end;
  359.     pvioCursorInfo.cx = (USHORT)1;
  360.     pvioCursorInfo.attr = hidden;
  361.     VioSetCurType((PVIOCURSORINFO)&pvioCursorInfo,0);
  362. #  endif
  363. # endif
  364.  
  365. # ifdef DOS
  366.     regs.h.ah = 0x01;
  367.     regs.h.al = (unsigned char)_cursvar.scrnmode;  /* if not set, some BIOSes hang */
  368.     regs.h.ch = (unsigned char)start;
  369.     regs.h.cl = (unsigned char)end;
  370.     int86(0x10, ®s, ®s);
  371. # endif
  372.     return( ret_vis );
  373. #endif
  374.  
  375. #if defined (XCURSES)
  376.     XCurses_display_cursor(_cursvar.cursrow,_cursvar.curscol,
  377.         curscr->_y[_cursvar.cursrow][_cursvar.curscol],
  378.         _cursvar.cursrow,_cursvar.curscol,
  379.         curscr->_y[_cursvar.cursrow][_cursvar.curscol]);
  380.     return(ret_vis);
  381. #endif
  382.  
  383. }
  384. /***********************************************************************/
  385. int    napms(int ms)
  386. /***********************************************************************/
  387. {
  388.     return(delay_output(ms));
  389. }
  390.